Page 2 of 4 FirstFirst 1234 LastLast
Results 11 to 20 of 37

Thread: Help with Weapon Swapping

  1. #11
    Purple Developer Purple Elephant1au's Avatar
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    1,259

    Default

    Ok i will exec it after level waittill spawn and see how it goes

    But as i mentioned , when your in the freezetag spectate mode , ie after you have been killed and your spectating the frozen bodies etc , the script runs again (cause i saw the iprint again) , so i think the spawn event might detect it . Because with the freezetag , your spawned after you die but your like glued to players etc not truly in spectate mode but still alive in the game until you either get melted ( thus the respawn part) or your team loses ( then you die fully again )

    But would that cause the script to fail ? the rest of the script works fine even if it repeated , but im guessing the weapon swap part with the local.player.swap = 1 part doesnt like to be repeated
    Last edited by Purple Elephant1au; February 8th, 2013 at 05:03 PM.

    Purple's Playground
    OBJ :
    103.29.85.127:12203
    xfire: purpleelephant1au
    email: purpleelephant1au@gmail.com
    skydrive: PurpleElephantSkydrive




  2. #12
    Developer Sor's Avatar
    Join Date
    Aug 2010
    Location
    The Medieval City of Bruges
    Posts
    747

    Default

    Yeah, just confirmed, it detects respawn, just not the one after restarts... Also, the registration lasts one map session and survives restarts
    so it doesn't really matter when it's called, but before waittill spawn would be cleaner in this case. Sorry about that.

    If the script repeated twice each time, and you invert the boolean at each run, then every action gets undone.
    This still doesn't explain why it's executed twice in the first place though. But I haven't check your latest script yet.
    It's midnight here, so I'll take a look tomorrow.
    Morpheus Script (MoH) => You try to shoot yourself in the foot only to discover that MorpheusScript already shot your foot for you.

  3. #13
    Purple Developer Purple Elephant1au's Avatar
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    1,259

    Default

    Yea your help is much appreciated
    Last edited by Purple Elephant1au; February 9th, 2013 at 04:12 PM.

    Purple's Playground
    OBJ :
    103.29.85.127:12203
    xfire: purpleelephant1au
    email: purpleelephant1au@gmail.com
    skydrive: PurpleElephantSkydrive




  4. #14
    Purple Developer Purple Elephant1au's Avatar
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    1,259

    Default

    When i exec it after level waittil spawn , it causes the server to crash after roundend , had to change it back for it to work without crashing server

    Code:
    Crash Recover Attempt will take place!
    Execution path:
     --> [0xffffe410]
     --> /lib/libc.so.6(abort+0x101) [0x7b4701]
     --> /usr/lib/libstdc++.so.5 [0xf7f98157]
     --> /usr/lib/libstdc++.so.5 [0xf7f981a4]
     --> /usr/lib/libstdc++.so.5 [0xf7f98316]
     --> ./fgamededmohaa.so(_ZN12ScriptMaster18CreateScriptThreadEP10GameScriptP8Listener9const_str+0x1aa) [0xf60c809a]
     --> ./fgamededmohaa.so(_ZN8Listener20CreateScriptInternalERK14ScriptVariable+0x271) [0xf61a0451]
     --> ./fgamededmohaa.so(_ZN8Listener21ExecuteScriptInternalEP13Event_GAMEDLLR14ScriptVariable+0x28) [0xf6199bb8]
     --> ./fgamededmohaa.so(_ZN8Listener13ExecuteScriptEP13Event_GAMEDLL+0x29) [0xf6199a19]
     --> ./fgameded.so(ExecuteScript+0x2e) [0xf646fa03]
     --> ./fgameded.so(Player_Respawn_hook+0x83) [0xf6477cc9]
     --> ./fgamededmohaa.so(_ZN8Listener12ProcessEventEP13Event_GAMEDLL+0x4f) [0xf61a190f]
     --> ./fgamededmohaa.so(L_ProcessPendingEvents+0x4e) [0xf61a23ae]
     --> ./fgamededmohaa.so(G_RunFrame+0x1cf) [0xf617afef]
     --> ./fgameded.so(G_RunFrame+0x7d1) [0xf6476b8a]
     --> ./mohaa_lnxded [0x808d7ab]
     --> ./mohaa_lnxded [0x8067486]
     --> ./mohaa_lnxded [0x809726e]
     --> /lib/libc.so.6(__libc_start_main+0xdc) [0x79fe9c]
     --> ./mohaa_lnxded(_Znwj+0x71) [0x8049c41]
    mlds.sh: Server Exited
    mlds.sh: To exit loop hit CTRL-C
    mlds.sh: Sleeping for 15 seconds
    mlds.sh: Loop Restarting now
    mlds.sh: To exit loop hit CTRL-C
    mlds.sh: Starting Server
    --- Common Initialization ---

    Purple's Playground
    OBJ :
    103.29.85.127:12203
    xfire: purpleelephant1au
    email: purpleelephant1au@gmail.com
    skydrive: PurpleElephantSkydrive




  5. #15
    Purple Developer Purple Elephant1au's Avatar
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    1,259

    Default

    Ok

    This is a revised script , i tried cleaning it up abit

    Code:
    main:
    
    local.result = registerev "spawn" global/custom/weapons.scr::spawn
    local.result = registerev "connected" global/custom/weapons.scr::connected
    
    thread get_cvars
    
    thread weapon_message
    
    teamswitchdelay .2
    
    end
    
    connected local.player: 
    
    thread spawn local.player
    
    end
    
    spawn local.player:
    
    waitthread weapon_check local.player
    
    thread weapon_swap local.player
    
    end
    
    //////////////////////////////////////
    
    weapon_check local.player:
    
    wait 0.6
    
    ////////////////////////////////////////////////////////////
    ////////////// Weapon Check Part ///////////////////////////
    
    
    
    if(local.player != NULL && local.player != NIL && isAlive(local.player) && local.player.dmteam != spectator && !local.player.checked)
    {
    
    local.player iprint "Start Check"
    
    		local.player weaponcommand dual targetname ("weap" + local.player.entnum )
    		local.player.weapon = $("weap" + local.player.entnum ).model
    		
    		if(local.player.weapon != NIL && local.player.weapon != NULL)
    		
    		{
    				for (local.i = 1; local.i <= level.notallowed.size; local.i++) 
    				{
    					   if(local.player.weapon == level.notallowed[local.i])
    						{	
    								local.player take level.notallowed[local.i]
    								local.player iprint "Not Allowed"
    														if(getcvar(pe_weapon_choice) != "1")
    														{ 
    														local.player give models/weapons/KAR98sniper.tik
    														local.player use models/weapons/KAR98sniper.tik
    														}
    														if(getcvar(pe_weapon_choice) == "1")
    														{
    														local.player spectator
    														local.player stufftext "pushmenu SelectPrimaryWeapon"
    														}
    								
    										if(getcvar(pe_weapon_message) == "1") 
    														{
    															local.player iprint ("The Weapon you chose is unavailable") 1
    															local.player iprint (level.allowed) 1
    															//local.player iprint ("So here is a Sniper") 1	
    														}
    								
    						}
    						local.player.checked = 1
    						
    									
    				}
    		}
    		
    
    
    
    local.player iprint "End Check"
    
    }
    
    wait 0.5
    local.player.checked = 0	
    end
    
    
    ////////////////////////////////////////////////////////////
    ////////////// Weapon Swap Part ///////////////////////////
    
    
    weapon_swap local.player:
    
        if (getcvar(pe_weapon_swap) == "1") 
        {
            if(local.player && !local.player.swapped && isAlive(local.player) && local.player.dmteam == "allies")
    		
    	      {
                local.player iprint "Swap Start"
                local.player weaponcommand dual targetname ("weap" + local.player.entnum )
                local.player.weapon = $("weap" + local.player.entnum ).model
                
                switch(local.player.weapon)
                {
                    case "models/weapons/springfield.tik":
                        local.take = "models/weapons/springfield.tik"
                        local.takename = "Springfield"
                        local.give = "models/weapons/KAR98sniper.tik"
                        local.givename = "Kar98Sniper"
                    break
                     
                    case "models/weapons/m1_garand.tik":
                        local.take = "models/weapons/m1_garand.tik"
                        local.takename = " M1 Garand"
                        local.give = "models/weapons/kar98.tik"
                        local.givename = "Mausar kar98"
                    break
                    default:
                        end
                }
                
                wait 1    
            
                if(local.player && isAlive(local.player) && local.player.dmteam != "spectator")
                {
                    if(local.player.swap == "1")
                    {
                        local.player take local.take
                        local.player give local.give
                        local.player iprint (local.takename + " has been swapped for " + local.givename) 1
                        local.player ammo rifle -42
                        local.player use local.give
                        local.player iprint ("Hold 'Use' again to change back") 1
    
    
                        local.wait = 3.0
                        while(local.player.useheld && 0.0 < local.wait) {
                            wait 0.25
                            local.wait -= 0.25
                        }
                        
                        if (local.wait <= 0.0) {
                            local.player take local.give
                            local.player give local.take
                            local.player ammo rifle -42
                            local.player use local.take
                            local.player.swap = "0"
    						
                        }
    					local.player.swapped = 1 
                    } else {    
                        local.player iprint ("Hold 'Use' for 3 Seconds to change") 1
                        local.wait = 2.0
                        while(local.player.useheld && 0.0 < local.wait) {
                            wait 0.25
                            local.wait -= 0.25
                        }
                        
                        if (local.wait <= 0.0) {
                            local.player take local.take
                            local.player give local.give
                            local.player ammo rifle -42
                            local.player iprint (local.takename + " has been swapped for " + local.givename) 1
                            local.player use local.give
                            local.player.swap = "1"
    						local.player.swapped = 1 
    						
                        }
                    }
    				local.player.swapped = 1  
    				local.player iprint "Swap End"
    				
    				  
                }
    			
            }
          
        }
     wait 0.5
    local.player.swapped = 0
    
    
    
    end
    
    get_cvars:
    
    //////////////////////////////
    level.notallowed[1] = ""
    level.notallowed[2] = ""
    level.notallowed[3] = ""
    level.notallowed[4] = ""
    level.notallowed[5] = ""
    level.notallowed[6] = ""
    level.notallowed[7] = ""
    level.notallowed[8] = ""
    level.notallowed[9] = ""
    level.notallowed[10] = ""
    level.notallowed[11] = ""
    //////////////////////////////////////////////////////////////
    //////////////////////  Get Cvars ////////////////////////////
    
    if(getcvar(PE_mg) == "0")
    		{
    			level.notallowed[1] = "models/weapons/bar.tik"
    			level.notallowed[2] = "models/weapons/mp44.tik"
    		}
    
    if(getcvar(PE_rocket) == "0")
    		{
    			level.notallowed[3] = "models/weapons/bazooka.tik"
    			level.notallowed[4] = "models/weapons/panzerschreck.tik"
    		}
    
    if(getcvar(PE_shotgun) == "0")
    		{
    			level.notallowed[5] = "models/weapons/shotgun.tik"
    		}
    
    if(getcvar(PE_rifle) == "0")
    		{
    			level.notallowed[6] = "models/weapons/m1_garand.tik"
    			level.notallowed[7] = "models/weapons/kar98.tik"
    		}
    
    if(getcvar(PE_sniper) == "0")
    		{
    			level.notallowed[8] = "models/weapons/springfield.tik"
    			level.notallowed[9] = "models/weapons/KAR98sniper.tik"
    		}
    
    if(getcvar(PE_smg) == "0")
    		{
    			level.notallowed[10] = "models/weapons/thompsonsmg.tik"
    			level.notallowed[11] = "models/weapons/mp40.tik"
    		}
    
    if(getcvar(PE_pistol) == "0")
    		{
    			level.player take "models/weapons/colt45.tik"
    			level.player take "models/weapons/p38.tik"
    		}
    
    if(getcvar(PE_grenade) == "0")
    		{
    			level.player take "models/weapons/m2frag_grenade.tik"
    			level.player take "models/weapons/steilhandgranate.tik"
    		}
    
    end
    /////////////////////////////////////////////////////////////
    /////////////////////// Message Part /////////////////////////
    
    weapon_message:
    
    level.allowed = "Allowed Weapons:"
        if (getcvar(pe_allweapons) == "1") 
            level.allowed += " All Weapons "
        else
        {
            if (getcvar(pe_pistol) == "1") 
                level.allowed += " Pistol,"
            if (getcvar(pe_rifle) == "1")
                level.allowed += " Rifle,"
            if (getcvar(pe_sniper) == "1") 
                level.allowed += " Sniper,"
            if (getcvar(pe_smg) == "1") 
                level.allowed += " SMG,"
            if (getcvar(pe_mg) == "1") 
                level.allowed += " MG,"
            if (getcvar(pe_grenade) == "1") 
                level.allowed += " Grenades,"
            if (getcvar(pe_shotgun) == "1") 
                level.allowed += " Shotgun,"
            if (getcvar(pe_rocket) == "1") 
                level.allowed += " Rocket,"
    
        }
    
    end


    Now it no longer repeats the entire script
    I added prints to tell me what parts start and what parts finish

    Now

    Weapon Check part


    ie Start Check and End Check

    Runs only Once , whether you be axis or allies, swapped or not swapped , whether it took your weapon or not if you choose wrong

    Swapping part


    ie Swap Start and Swap End

    Now this is where it gets weird , when the round hasnt started , works fine , they only appear once and you can swap and change

    As soon as the 2nd!! round starts , so after they die in first round, stuffs up come 2nd round , then the messages appear as follows:

    Code:
    Start Check
    Swap Start
    End Check
    Swap Start
    Hold 'Use' for 3 Seconds to change
    Swap End
    Hold 'Use' for 3 Seconds to change
    Swap End
    So its repeating itself on the swap part only , i dont no how the first swap start is before the end check even with the waitthread...
    And its making you choose to swap again every round

    Purple's Playground
    OBJ :
    103.29.85.127:12203
    xfire: purpleelephant1au
    email: purpleelephant1au@gmail.com
    skydrive: PurpleElephantSkydrive




  6. #16
    Developer Sor's Avatar
    Join Date
    Aug 2010
    Location
    The Medieval City of Bruges
    Posts
    747

    Default

    You script is being run twice regardless. The only thing that stops the first part from repeating itself is the 'local.player.checked' property.
    This is because of your 'connected' event. While it is true that the spawn event does not detect spawns at round restart or rcon restart,
    the connected event does which is probably why you did this:
    Code:
    connected local.player: 
    thread spawn local.player
     end
    Is respawning off or did you send all players to spectator before restarting the round? If all players were sent to spectator, the script will
    repeat itself. The script will also repeat itself for any player who was dead at the moment the round ended. The script will also be executed
    when a player connects to the server (without actually being spawned).

    Try something like this instead:
    Code:
    connected local.player:
    if ((isAlive local.player) && local.player.dmteam != "spectator") {
        thread spawn local.player
    }
    end
    That should do it. If not, try adding a waitframe before the if() statement. Or you could simply do this:
    Code:
    spawn local.player:
    local.player.spawning = 1;
    
    waitthread weapon_check local.player
    thread weapon_swap local.player
    
    //waitframe
    local.player.spawning = 0;
    end
    And in the connected event you simply add the check to the if() statement:
    Code:
    connected local.player:
    if ((isAlive local.player) && local.player.dmteam != "spectator" && !local.player.spawning) {
        thread spawn local.player
    }
    end
    If a player isn't alive (or is a spectator) upon the occurrence of this event, then he simply connected to the server.
    Else, a restart has taken place, where alive players were respawned so quickly, the spawn event doesn't pick it up.
    If the spawn event doesn't pick it up, the player's .spawning property won't equal to 1.

    This is what I noticed at first glance, though.
    Last edited by Sor; February 10th, 2013 at 07:25 AM.
    Morpheus Script (MoH) => You try to shoot yourself in the foot only to discover that MorpheusScript already shot your foot for you.

  7. #17
    Purple Developer Purple Elephant1au's Avatar
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    1,259

    Default

    Ok

    I tried all that ,
    still repeated at same point ,
    then i got rid of the connection handler part all together and it stopped repeating , but causes another problem

    When you die and get melted again , it goes through the Start check and end check as it should , but then comes Swap start then nothing else , doesnt continue or end , doesnt let you choose to change weapons...

    And its still not remembering your choice in the matter , but i think thats cause the local.player.swap resets each time you spawn again so youll have to do it each time.

    Also tried adding local.player.mef_pstate == "PSTATE_ALIVE" to the statements , so as to stop it running when player is in ftag spec , but then it stops it running at all, cause that might be where its stopping aswell..

    Purple's Playground
    OBJ :
    103.29.85.127:12203
    xfire: purpleelephant1au
    email: purpleelephant1au@gmail.com
    skydrive: PurpleElephantSkydrive




  8. #18
    Developer Sor's Avatar
    Join Date
    Aug 2010
    Location
    The Medieval City of Bruges
    Posts
    747

    Default

    Why don't you undo the spawn event as well and use this instead:
    Code:
    level.mef_pstatecallbacks.spawned = global/custom/weapons.scr::spawn
    Morpheus Script (MoH) => You try to shoot yourself in the foot only to discover that MorpheusScript already shot your foot for you.

  9. #19
    Purple Developer Purple Elephant1au's Avatar
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    1,259

    Default

    Cause that would be too easy lol

    It doesnt repeat at all now ,

    but still doesnt remember the local.player.swap = 1

    Im guessing it resets every time the round ends , cause you can die multiple times and get melted again and it will remember it , but as soon as round ends , you have to choose again, but its better then nothing

    Thanks so much :P

    EDIT::

    Also after seeing you reading this
    http://www.x-null.net/forums/showthr...waittill-spawn

    I tried a level watiil spawn before the weapon_swap , but it still didnt work, then i moved it up before the level.mef_pstatecallbacks.spawned = global/custom/weapons.scr::spawn but still no luck
    Last edited by Purple Elephant1au; February 10th, 2013 at 09:04 AM.

    Purple's Playground
    OBJ :
    103.29.85.127:12203
    xfire: purpleelephant1au
    email: purpleelephant1au@gmail.com
    skydrive: PurpleElephantSkydrive




  10. #20
    Developer Sor's Avatar
    Join Date
    Aug 2010
    Location
    The Medieval City of Bruges
    Posts
    747

    Default

    That's probably because everything AFTER level waittill spawn will be re-executed but everything before it won't.
    In other words, only level variables persist (since restart apparently deletes game variables as well).

    In case of restart or mapchange, the $player array and all entities that weren't present in the .bsp (i.e. not just the player) are deleted.
    As each client "enters the battle" after the restart, a player entity is created that is associated with the client.
    This means all entity properties & 'local' & 'group' (ScriptThreads are entities) variables are lost as well.

    This is also why the reborn spawn event doesn't detect this spawn, but the connected event does since that is what it is looking for: the creation of a player entity.
    Last edited by Sor; February 10th, 2013 at 12:05 PM.
    Morpheus Script (MoH) => You try to shoot yourself in the foot only to discover that MorpheusScript already shot your foot for you.

Page 2 of 4 FirstFirst 1234 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •